/****************************************************************
irrEventManager
Copyright (C) 2007-2008 Keith Holbrook
This file is part of "irrEventManager".
For conditions of distribution and use, see copyright notice in irrEventManagerr.h

*****************************************************************/
//_IRR_DEBUG_BREAK_IF( )

#ifndef _IRR_CEVENTMANAGER_H
#define _IRR_CEVENTMANAGER_H

//#include "eventmancfg.h"

#include <memory.h>
#include <cstdlib>
#include "irrarray.h"
#include "keycodes.h"
#include "IEventManager.h"
#include "CEventEx.h"


//!I'm using bit arrays to store key and mouse flags
/** if compiling the manager,you can disable it by commenting this out*/
#define _IRREVENTMANAGER_USEBITS

namespace irr
{

    class CEventManager : public  IEventManager
    {

     public:
        CEventManager();
        ~CEventManager();
        bool OnEvent(const SEvent&);

        virtual void setKeyDelay(const u32 d);
        virtual u32  keyDelay();
        virtual wchar_t keyChar();
        virtual bool keyDown(EKEY_CODE);
        virtual bool keyClick(EKEY_CODE) ;
        virtual s32 anyKeydown();
        virtual EKEY_CODE keyUp();

        ///mouse
        const core::position2d<s32>& mousePos();
        f32  mouseWheel();
        bool mouseDown(EMOUSE_BUTTONS);
        bool mouseUp(EMOUSE_BUTTONS);
        bool mouseClick(EMOUSE_BUTTONS);

        virtual void update();

        virtual void removeAll();

        virtual  IEventEx* getEvent(EEVENT_TYPE,gui::EGUI_EVENT_TYPE guitype=gui::EGET_ELEMENT_FOCUS_LOST,s32 startId=999);

        virtual  IEventEx* getKeyEvent(s32 startId=999);

        virtual  IEventEx* getMouseEvent(s32 startId=999);

        virtual  IEventEx* getJoyEvent(s32 startId=999);

        virtual  IEventEx* getGuiEvent(gui::EGUI_EVENT_TYPE,s32 startId=999);

        virtual  IEventEx* getUserEvent(s32 startId=999);

        virtual IEventEx* getLogEvent(s32 startId=999);

        virtual void removeAllReceiversByData(void*);

        virtual void removeAllReceiversByObject(void*);

        virtual void removeAllGuiReceiversByData(void*);

        virtual void removeAllGuiReceiversByCaller(void*);

        virtual void removeAllGuiReceiversByObject(void*);

        virtual u32 getReceiverCount();


    private:





///mouse
#ifdef _IRREVENTMANAGER_USEBITS
        u8  mouseKeys[3];
#else
        u8  mouseKeys[3];
        u8  mouseKeysOld[3];
        u8  mouseKeysOld2[3];
        s32 lastMouseUp;
#endif

        core::position2d<irr::s32> msePos;
        f32   wheel;
        u32  wheelFlag;

///key

        u32 delay,dt;
        wchar_t chr;
        u32 lastKeyup;

#ifdef _IRREVENTMANAGER_USEBITS
        u8   Keys[irr::KEY_KEY_CODES_COUNT];
#else
        u8  Keys[irr::KEY_KEY_CODES_COUNT];
        u8  KeysOld[irr::KEY_KEY_CODES_COUNT];
        u8  KeysOld2[irr::KEY_KEY_CODES_COUNT];
#endif


///Events
        CKeyEventEx* KeyEvent;
        CMouseEventEx* MouseEvent;
        core::array<CGuiEventEx*> guiEvents;
       // CGuiEventEx** GuiEvents;
        CLogEventEx* LogEvent;
        CUserEventEx* UserEvent;
        CJoyEventEx* JoyEvent;

        CEventManager(CEventManager&);
        CEventManager & operator = (const CEventManager&);
       // ILogger* Logger;


    };


}


#endif // CINPUTMANAGER_H

